<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>restPassword</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/login.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    
</head>

<body>
    <div class="container-login">
        <div class="container-pic">
            <img src="pic/computer.png" width="350px">
        </div>
        <div class="login-dialog">
            <h3>修改密码</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" name="userName" id="userName" class="form-control" placeholder="输入您的电子邮箱">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" name="password1" id="password1" class="form-control" placeholder="8-16位数字或字母">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" name="password2" id="password2" class="form-control" placeholder="重新输入密码">
            </div>
            <div class="row">
                <span>验证码</span>
                <input type="text" name="captcha" id="captcha" class="form-control" placeholder="验证码">
            </div>
            <div class="row">
                <button onclick="getCaptcha()" style="color: blue;">获取验证码</button>
                <button type="button" class="btn btn-info btn-lg" onclick="verify()">提交</button>
            </div>
        </div>
    </div>
    <script src="js/jquery.min.js"></script>

    <script>
        function getCaptcha() {
            $.ajax({
                url: "/captcha/send",
                type: "post",
                data: {
                    userName: $("#userName").val()
                },
                success: function (result) {
                    if (result.code == "SUCCESS") {
                        alert("获取验证码成功！");
                    } else {
                        alert(result.errMsg);
                    }
                }
            });
        }
        function verify() {
            $.ajax({
                url: "/captcha/verify",
                type: "post",
                data: {
                    captcha: $("#captcha").val()
                },
                success: function (result) {
                    if (result.code == "SUCCESS") {
                        rest();
                    } else {
                        alert(result.errMsg);
                    }
                }
            });
        }
        function rest() {
            $.ajax({
                url:"/user/rest",
                type:"post",
                data:{
                    userName:$("#userName").val(),
                    password1:$("#password1").val(),
                    password2: $("#password2").val(),
                },
                success:function(result) {
                    if(result.code == "SUCCESS") {
                        alert("密码已重置！");
                        location.href = "login.html";
                    }else{
                        alert(result.errMsg);
                    }
                }
            });
        }
    </script>
</body>

</html>